package com.wutong.eams.mapper;

import com.wutong.eams.entity.User;
import com.wutong.eams.other.ConditionBuilder;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {

    @Override
    default Class<User> getEntityClass() {
        return User.class;
    }
    @Override
    default String getTableName() {
        return "users";
    }

    default List<User> selectByUsername(String username) {
        ConditionBuilder conditionBuilder = new ConditionBuilder();
        conditionBuilder.where("username", ConditionBuilder.Operator.EQUAL, username);
        return select(conditionBuilder);
    }

    default User selectByUserId(Integer userId) {
        ConditionBuilder conditionBuilder = new ConditionBuilder();
        conditionBuilder.where("userId", ConditionBuilder.Operator.EQUAL, userId);
        return selectOne(conditionBuilder);
    }

    default int updateByUserId(User user) {
        ConditionBuilder conditionBuilder = new ConditionBuilder();
        conditionBuilder.where("userId", ConditionBuilder.Operator.EQUAL, user.getUserId());
        return update(user, conditionBuilder);
    }

}
